#ifndef FOUNDATION_PROTOCOL_XCOMPARSER_H
#define FOUNDATION_PROTOCOL_XCOMPARSER_H
#include <map>
#include <memory>
#include "template.h"
#include <stack>
#include <tuple>
#include "xcom_node.h"

namespace protocol {
class XComParser {
public:
	XComParser() = default;
	bool LoadXComFile(const std::string &filePath);
	std::shared_ptr<XComNode> GetXComNode(const std::string &id);
	std::string WrapToken(const std::string &line, int32_t &pos);
	void Clear();

private:
	bool ParseLine(const std::string &line);

	bool ParseKV(const std::string &key, const std::string &value);
	void ParseTemplate();

	std::string GetCorrespStr(
		const std::string &line, int32_t &pos, const std::vector<char> &corr);

	friend class XComParserTest;

private:
	std::stack<std::string> stackNode_;
	std::vector<std::string> stackKey_;
	std::vector<std::string> stackKVs_;
	std::map<std::string, std::shared_ptr<XComNode> > mapXComNodes_;
};
} // namespace protocol
#endif // FOUNDATION_PROTOCOL_XCOMPARSER_H